MISSION = {}

MISSION_SABOTAGE_SINGLE = 0

MISSION[MISSION_SABOTAGE_SINGLE] = {
	Structure={EMAIL_GREETING,EMAIL_BUSINESS,EMAIL_BREAK,EMAIL_BREAK,EMAIL_MISSION_SABOTAGE_SINGLE,EMAIL_BREAK,EMAIL_BREAK,EMAIL_PAYMENT,EMAIL_CAUTION,EMAIL_BREAK,EMAIL_BREAK,EMAIL_HOW_TO_CONTACT,EMAIL_SIGNATURE},
	Payment_Range={100,150}, -- For the lowest level
	Payment_Multiplier=0.2, -- For every difficulty level, payment = core payment + (core payment * multiplier * level)
	UsesFiles=true,
	Single=true,
	Files={1,1}
}

FILE_EXTENSIONS = {".exe",".dat",".txt",".log",".dll",".jpg"}
if SERVER then
	MISSION_VARIABLES_STORE = {}
	MISSION_VARIABLES_STORE.FName = string.Explode("\n",file.Read("shadow/fnames.txt"))
	MISSION_VARIABLES_STORE.LName = string.Explode("\n",file.Read("shadow/lnames.txt"))
	MISSION_VARIABLES_STORE.Business = string.Explode("\n",file.Read("shadow/corporations.txt"))
	
	function CorporationAddress(name)
		local split = string.Explode(" of ",name)
		
		local str = ""
		if split[2] then -- If the name is X X of X, then use the after X first.
			str = str..split[2].."_"
		end
		
		local plode = string.Explode(" ",split[1])
		local c=1
		for k,v in pairs(plode) do
			if c<=2 then -- Don't get more than 2 abbreviations in it.
				str = str..string.sub(v,1,4) -- Get the first four letters of each word included
			else
				break
			end
			c=c+1
		end
		
		return string.gsub(string.lower(str)," ","-")
	end
	
	function GenerateFile(bus)
		return string.lower(string.sub(bus,1,2)).."-"..math.random(1000,50000)..table.Random(FILE_EXTENSIONS)
	end
	
	function GenerateRandomMissions(num)
		print(-1)
		if not MissionList then MissionList = {} end
		if not MissionTypes then
			MissionTypes = {}
			for mtype,v in pairs(MISSION) do
				table.insert(MissionTypes,mtype)
			end
		end
		print(0)
		
		for i=1,num do
			print(i,1)
			local mtype = table.Random(MissionTypes)
			local employer,target = table.Random(ORGAN),table.Random(ORGAN)
			
			print(2)
			local tserver -- Target server
			if target.ServerType==ORG_CENTRALIZED then
				tserver = GetServerFromType(target.CorpName,ORG_MAINFRAME)
			else
				-- TODO: Make this pick from a decentralized database
				tserver = GetServerFromType(target.CorpName,ORG_MAINFRAME)
			end
			
			print(3,target.CorpName,employer.CorpName,tserver)
			local ptype = employer.Personality
			
			local short = MISSION[mtype]
			
			local diff = target.Difficulty
			local pay = math.random(short.Payment_Range[1],short.Payment_Range[2])
			pay = math.RoundToNearest(pay + (pay * (short.Payment_Multiplier * (diff))),10)
			
			print(4,ptype,diff,pay)
			local store = MISSION_VARIABLES_STORE
			
			local files = {}
			if short.UsesFiles then
				for i=1,math.random(short.Files[1],short.Files[2]) do
					local fil = table.Random(target.Servers[tserver].Files)
					table.insert(files,fil)
				end
				
				if #files<1 then files = {"LOL DECENTRALIZED!!"} end -- Make this proper.
			end
			print(5)
			
			local recruiter = table.Random(employer.Servers[GetServerFromType(employer.CorpName,ORG_INTERNAL_SERVICES)].Employees)
			-- Set up the mission variables
			
			print(6)
			local fname,lname = string.Capitalize(recruiter[1]),string.Capitalize(recruiter[2])
			local vars = {}
			vars.FName = fname
			vars.LName = lname
			vars.Business = employer.CorpName
			vars.Payment = pay
			vars.Email = string.lower(string.sub(fname,1,1))..string.lower(lname).."@"..CorporationAddress(employer.CorpName)..".net"
			vars.Target_Business = target.CorpName
			if short.UsesFiles then
				if short.Single then
					vars.Target_File = table.concat(files,", ")
				else
					vars.Target_Files = table.concat(files,", ")
				end
			end
			
			print(7)
			table.insert(MissionList,{Pay=pay,Variables=vars,MissionType=mtype,Personality=ptype})
		end
	end
end
			
	